package com.lantosec.hmrp.modules.system.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import com.lantosec.hmrp.core.util.UUIDUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.system.entity.UserAutograph;
import com.lantosec.hmrp.modules.system.service.IUserAutographService;
import com.lantosec.hmrp.modules.system.vo.UserAutographVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 *  控制器
 *
 * @author AutoCode
 * @since 2020-06-28
 */
@Api(value = "用户签名控制器", tags = "用户签名控制器")
@RestController
@RequestMapping("/system/user/autograph")
@Log4j2
public class UserAutographController extends BaseController {
    @Autowired
    private IUserAutographService service;

    @GetMapping("all")
    @ApiOperation(value = "查询全部")
    public Result<List<UserAutographVO>> all(@ApiParam(value = "用户ID", required = true) @RequestParam(name="userId") String userId){
        List<UserAutographVO> userAutographVOS = service.getAll(userId);
        return Result.ok(userAutographVOS);
    }


    @GetMapping("get/{userId}")
    @ApiOperation(value = "查询用户主签名")
    public Result<UserAutographVO> get(@ApiParam(value = "用户ID", required = true) @PathVariable(name="userId") String userId){
        return Result.ok(service.getByUserId(userId));
    }

    @PostMapping("create")
    @ControllerLog(name = "新增用户签名", type = LogType.add)
    @ApiOperation(value = "新增数据")
    public Result<Result> create(@ApiParam(value = "VO对象", required = true) @RequestBody @Validated UserAutographVO vo){
        Result result = service.saveUserAutograph(vo);
        return result;
    }

    @PutMapping("update")
    @ControllerLog(name = "修改用户签名", type = LogType.update)
    @ApiOperation(value = "修改数据")
    public Result<Void> update(@ApiParam(value = "VO对象", required = true) @RequestBody UserAutographVO vo){
        UserAutograph entity = vo.convertToEntity();
        service.updateById(entity);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除用户签名", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
